package com.zeus.monitor;

import com.zeus.monitor.aspect.PrometheusAspect;
import com.zeus.monitor.metrics.ZeusMetrics;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.MetricsServlet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import javax.servlet.http.HttpServlet;

/**
 * @author magic
 * @date 2018/11/8/008 15:20
 * @version 1.0
 * Description PrometheusAutoConfiguration
 */
@Configuration
@EnableAspectJAutoProxy
public class PrometheusAutoConfiguration {

    @Bean
    public PrometheusAspect prometheusAspect(){
        PrometheusAspect prometheusAspect = new PrometheusAspect();
        return prometheusAspect;
    }

    @Bean
    public ZeusMetrics zeusMetrics(){
        ZeusMetrics zeusMetrics = new ZeusMetrics();
        return zeusMetrics;
    }

    @Bean
    @ConditionalOnClass(HttpServlet.class)
    public ServletRegistrationBean servletRegistrationBean(){
        return new ServletRegistrationBean(new MetricsServlet(CollectorRegistry.defaultRegistry),"/metrics");
    }

}
